package com.tianshuo.main;

import com.tianshuo.config.AppConf;
import com.tianshuo.config.AppConfig;
import com.tianshuo.model.BdObject;
import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @ClassName : BeanDefinitionTest
 * @Description : Beandefinition测试
 * @Author : tianshuo
 * @Date: 2020-08-26 15:57
 */
public class BeanDefinitionTest {

	public static void main(String[] args) {


		AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
		ac.register(AppConfig.class);

		//通过AnnotatedBeanDefinition构建配置类 ac.register(AppConfig.class);可以使用如下配置替代
		AnnotatedGenericBeanDefinition annotatedGenericBeanDefinition = new AnnotatedGenericBeanDefinition(AppConfig.class);
		annotatedGenericBeanDefinition.setBeanClass(AppConf.class);
		ac.registerBeanDefinition("appConf", annotatedGenericBeanDefinition);

		// 构建通用的GenericBeanDefinition
		GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
		genericBeanDefinition.setBeanClass(BdObject.class);
		ac.registerBeanDefinition("dbObject", genericBeanDefinition);

		ac.refresh();


		System.out.println(ac.getBean("dbObject"));
		System.out.println(ac.getBean(AppConf.class));

		System.out.println(ac.getBean("user"));

	}
}

